<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%post}}".
 *
 * @property integer $id
 * @property string $title
 * @property integer $cid
 * @property integer $thumb
 * @property string $description
 * @property string $content
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $is_top
 * @property string $from
 * @property integer $views
 * @property integer $user_id
 */
class Post extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%post}}';
    }

    public function behaviors()
    {
        return [
            TimestampBehavior::className()
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'content'], 'required'],
            [['cid', 'thumb', 'created_at', 'updated_at', 'is_top', 'views', 'user_id'], 'integer'],
            [['content'], 'string'],
            [['title'], 'string', 'max' => 80],
            [['description'], 'string', 'max' => 200],
            [['from'], 'string', 'max' => 10],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '文章标题',
            'cid' => '所属类别',
            'thumb' => '封面图',
            'description' => '简介',
            'content' => '文章内容',
            'created_at' => '添加时间',
            'updated_at' => '更新时间',
            'is_top' => '是否置顶',
            'from' => '文章来源',
            'views' => '浏览数',
            'user_id' => '发布者',
        ];
    }

    public function getCate(){
        return $this->hasOne(PostCate::className(), ['id'=>'cid']);
    }
}
